<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <title>浏览页面</title>
    <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="/app/admin/admin/css/reset.css"/>
</head>
<body>
<form class="layui-form">

    <div class="mainBox">
        <div class="main-container mr-5">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <span></span>
                    <input type="text" style="display:none" name="url" value="" />
                    <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="upload">
                        <i class="layui-icon layui-icon-upload"></i>上传文件
                    </button>
                </div>
                <div class="layui-input-block" style="color: #999;font-size: 14px;">请上传excel文件,按模板格式上传.
                    <a href="javascript:upload_template();">下载模板</a>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="button" class="pear-btn pear-btn-primary pear-btn-md" id="upload-btn">
                确认上传
            </button>
            <!--<button type="reset" class="pear-btn pear-btn-md">-->
            <!--重置-->
            <!--</button>-->
        </div>
    </div>
</form>
<script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
<script src="/app/admin/component/pear/pear.js"></script>
<script src="/app/admin/component/jsoneditor/jsoneditor.js"></script>
<script src="/app/admin/admin/js/permission.js"></script>
<script src="/app/admin/admin/js/functions.js"></script>
<script src="/app/admin/admin/js/md5.js"></script>
<script>
    // 字段 文件 url
    layui.use(["upload", "layer", "popup", "util"], function () {
        let input = layui.$("#url").prev();
        input.prev().html(layui.util.escape(input.val()));

        let loading = 1;
        layui.upload.render({
            elem: "#upload",
            accept: "file",
            auto:false,
            headers: get_header({}),
            url: "/app/admin/novel/index/upload2",
            field: "__file__",
            bindAction:'#upload-btn',
            before:function(){
                loading = layer.load();
            },
            done: function (res) {
                layer.close(loading);
                if (res.code) return layui.popup.failure(res.msg);
                var ids = res.data.ids;
                layui.popup.success('成功导入'+ids.length+'行内容',function () {
                    parent.layui.layer.closeAll();
                });
            }
            ,error: function(){
                layui.layer.closeAll();

                //请求异常回调
                layui.popup.failure('上传失败');
            }
        });
    });

    function upload_template() {
        location.href = '/app/admin/template/novel_upload2.xlsx';
    }

</script>
</body>
</html>